#pragma once

#include <imglib/image.h>
#include <imglib/bitmap.h>

namespace refine {

const static int fore_idx = -1; //this value in the map represents strict foreground pixel with which no variable is associated
const static int back_idx = -2;

typedef unsigned uint;

/// maps pixel of unknown region to variable number
class varmap
{
public:
	varmap(img::bitmap const & strict_fore, img::bitmap const & strict_back) 
		: map(strict_fore.dim())
	{
		num = 0;
		for (img::image<int>::iterator v = map.begin(); v != map.end(); ++v) {
			if (strict_fore[v]) {
				assert (!strict_back[v]);
				*v = fore_idx;
			}
			else if (strict_back[v])
				*v = back_idx;
			else
				*v = num++;
		}
	}
	/// the total number of variables
	uint count() const
		{ return num; }
	int operator[] (size_point const & p) const
		{ return map[p]; }
	bool variable(size_point const & p) const
		{ return map[p] >= 0; }
private:
	img::image<int> map;
	uint num;
};

} //namespace refine
